package com.halflife.framework.domain;

import org.springframework.ui.Model;

import java.util.Map;

/**
 * Created by zhaoyf on 2018/6/18.
 */
public class Page {
    private Integer pageNo;
    private Integer pageSize;
    private Integer totalPage;
    private Integer totalCount;

    public Page() {
        this.pageNo= 1;
        this.pageSize= 10;
    }

    public void setQueryParam(Map queryParam) {
        queryParam.put("currentPage_", (pageNo-1)*pageSize);
        queryParam.put("pageSize_", pageSize);
    }

    public void setMode(Model model) {

        model.addAttribute("totalPage",totalPage);
        model.addAttribute("pageNo",pageNo);
        model.addAttribute("pageSize",pageSize);
        model.addAttribute("totalCount",totalCount);
    }


    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        totalPage = totalCount/pageSize;
        if(totalCount%pageSize!= 0)
            totalPage++;
    }
}
